<?php
/**
 * Nordic Repository
 * 
 * LICENSE
 * 
 * The new BSD license is applied on this source-file. For further
 * information please visit http://license.nordic-dev.de/newbsd.txt
 * or send an email to andre.moelle@gmail.com.
 */

/**
 * This class represents one element of the validation-chain.
 * 
 * @category   Nordic
 * @package    Nordic_Validate
 * @copyright  2007 Nordic Development
 * @license    http://license.nordic-dev.de/newbsd.txt (New-BSD license)
 * @author     Andre Moelle <andre.moelle@gmail.com>
 * @version    $Id: Element.php 3 2007-07-08 09:21:42Z andre.moelle $
 */
class Nordic_Validate_Chain_Element implements Zend_Validate_Interface
{
	/**
	 * New message.
	 * 
	 * @var string
	 */
	private $_message;
	
	/**
	 * Validator.
	 * 
	 * @var Zend_Validate_Interface
	 */
	private $_validator;
	
	/**
	 * Value.
	 * 
	 * @var mixed
	 */
	private $_value;
	
	/**
	 * Constructor.
	 * 
	 * Makes the object ready.
	 * 
	 * @param Zend_Validate_Interface $validator validator that is a chain-element
	 * @param string $message new message
	 * @return void
	 */
	public function __construct (Zend_Validate_Interface $validator, $value, $message = '')
	{
		$this->_validator = $validator;
		$this->_message = $message;
		$this->_value = $value;
	}
	
	/**
	 * @see Zend_Validate_Interface::getErrors()
	 */
	public function getErrors ()
	{
		return array();
	}
	
	/**
	 * Overwrites the old message(s) with the given message.
	 * 
	 * @see Zend_Validate_Interface::getMessages()
	 */
	public function getMessages ()
	{
		$result = array();
		
		$msg = $this->_validator->getMessages();
		
		if(!$msg)
		{
			return array();
		}
		else if($this->_message != '')
		{
			return array($this->_message);
		}
		
		return $msg;
	}
	
	/**
	 * @see Zend_Validate_Interface::isValid()
	 */
	public function isValid ($value)
	{
		return $this->_validator->isValid($this->_value);
	}
}
?>